package com.youxue.teachin;

import android.content.Context;
import android.widget.Toast;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * 微信OAuth登录
 *
 * @author: zhiwei
 * @date: 2017-10-14 19:33
 * @version: 9.1.0
 */
public class WechatUtils {
    private static final String APP_ID = "wxc24a9c248da3ce11";
    public static final String STATE = "diandi_wx_login";

    private static Context mContext;
    public static IWXAPI mIWXAPI;

    public static void reqToWx(Context context) {
        mContext = context;
        mIWXAPI = WXAPIFactory.createWXAPI(context.getApplicationContext(), APP_ID, true);
        mIWXAPI.registerApp(APP_ID);
    }

    public static void wxLogin() {
        if (!mIWXAPI.isWXAppInstalled()) {
            Toast.makeText(mContext, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
            return;
        }
        final SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = STATE;
        mIWXAPI.sendReq(req);
    }



}
